﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using PlugNT.Cms.Core;
using PlugNT.Cms.Model;
using PlugNT.Cms.BLL;
using PlugNT.Cms.Page;

namespace PlugNT.Cms.Web.Admin.Pre_Create
{
    public partial class EditStaticTemplet : AdminPage
    {
        private Templet curTemplet = new Templet();

        protected void Page_Load(object sender, EventArgs e)
        {
            //权限检测
            this.CheckPower();

            if (!IsPostBack)
            {
                string type = (Request.QueryString["t"] == null) ? "" : Request.QueryString["t"].Trim();
                string clsid = (Request.QueryString["no"] == null) ? "" : Request.QueryString["no"].Trim();
                hidClsno.Value = clsid;
                TempletInfo model = curTemplet.GetTempletInfo(clsid);
                if (model != null)
                {
                    switch (type)
                    {
                        case "edit":
                            txtIndexTemplet.Text = model.indexfile;
                            txtListTemplet.Text = model.listfile;
                            txtContentTemplet.Text = model.showfile;
                            cbxCreateSiteMap.Checked = (model.ismap == 1);
                            break;
                        case "delete":
                            Delete(clsid);
                            break;
                        default:
                            break;
                    }
                }
                else
                {
                    Response.Redirect("../Message.aspx?message=<b>[模板绑定]</b>--失败！" + "&z=no");
                }

            }
        }


        private void Delete(string clsid)
        {
            if (curTemplet.Delete(clsid))
            {
                Response.Redirect("BindTemplet.aspx");
            }
            else
            {
                Response.Redirect("../Message.aspx?message=<b>[模板删除]</b>--失败！" + "&z=no");
            }
        }


        protected void Button_update_Click(object sender, EventArgs e)
        {

            string clsno = hidClsno.Value.Trim();
            if (clsno != "")
            {
                TempletInfo model = curTemplet.GetTempletInfo(clsno);
                string indexfile = txtIndexTemplet.Text.Trim();
                string listfile = txtListTemplet.Text.Trim();
                string showfile = txtContentTemplet.Text.Trim();
                int ismap = cbxCreateSiteMap.Checked ? 1 : 0;

                if (model != null)
                {
                    model.clsno = clsno;
                    model.indexfile = indexfile;
                    model.listfile = listfile;
                    model.showfile = showfile;
                    model.ismap = ismap;
                    if (curTemplet.UpdateByClsno(model))
                    {
                        Response.Redirect("BindTemplet.aspx");
                    }
                    else
                    {
                        Response.Redirect("../Message.aspx?message=<b>[模板修改]</b>--失败！" + "&z=no");
                    }
                }
                else
                {
                    Response.Redirect("../Message.aspx?message=<b>[模板修改]</b>--失败！" + "&z=no");
                }
            }
            else
            {
                Response.Redirect("../Message.aspx?message=<b>[模板修改]</b>--失败！" + "&z=no");
            }

        }

    }
}
